#include "syntaxhighlighter.h"

//---------------------------------------------
/**
 * @brief SyntaxHighlighter::SyntaxHighlighter
 * @param parent
 */
SyntaxHighlighter::SyntaxHighlighter (QTextDocument *parent) :
    QSyntaxHighlighter (parent)
{
    m_config = new Config (0) ;
}
//------------------------------------------------
/**
 * @brief SyntaxHighlighter::~SyntaxHighlighter
 */
SyntaxHighlighter::~SyntaxHighlighter ()
{
    delete m_config;
}

//------------------------------------------------------------
/**
 * @brief SyntaxHighlighter::highlightBlock
 * @param text
 */
void SyntaxHighlighter::highlightBlock (const QString &text)
{
    // préparer le format "souligné en vaguelettes"
    QTextCharFormat alertFormat;
    alertFormat.setUnderlineColor (m_config->optionUnderlineColor ());
    alertFormat.setUnderlineStyle (QTextCharFormat::SpellCheckUnderline);
//    alertFormat.setForeground (QBrush (QColor (255,200,200)));

    QStringList misspelled (m_spell.misspelledWords (text));

    foreach (const QString& badWord, misspelled) {
        int index = text.indexOf (badWord);
        while (index >= 0) {
            int length = badWord.length ();
            setFormat (index, length, alertFormat);
            index = text.indexOf (badWord, index + length);
        }
    }


}
